package com.bw.sparksql1.job1

import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SparkSession}

/**
  *
  */
case class Person1(var name:String,var age:Int)
object Job6 {
    def main(args: Array[String]): Unit = {
      Logger.getLogger("org").setLevel(Level.ERROR)
      val spark = SparkSession
        .builder()
        .master("local")
        .appName("Spark SQL basic example")
        .getOrCreate()

      val rdd1 = spark.sparkContext.textFile("person4.txt")
      import spark.implicits._
      val rdd2 = rdd1.map(line => Person1(line.split(",")(0), line.split(",")(1).trim.toInt))
      val dataFrame1 = rdd2.toDF()
      dataFrame1.createOrReplaceTempView("person")
      spark.sql("select count(*) from person").show()
    }
}